<?php

class m111005_065936_account extends CDbMigration {
	public function safeUp() {
		$this
			->createTable('erp_account_receivable',
				array(
					'id' => 'pk',
					'projectId' => 'int',
					'token' => 'string',
					'receiveDate' => 'date',
					'price' => 'decimal(16,2)',
					'note' => 'string',
					'altMode' => 'boolean',
					'createTime' => 'datetime',
					'createUserId' => 'int',
					'updateTime' => 'datetime',
					'updateUserId' => 'int',
				));
		$this
			->createIndex("account_receivable_create_user_id", 'erp_account_receivable',
				'createUserId');
		$this
			->addForeignKey('fk_account_receivable_create_user_id', 'erp_account_receivable',
				'createUserId', 'erp_user', 'id', 'SET NULL', 'CASCADE');
		$this
			->createIndex("account_receivable_update_user_id", 'erp_account_receivable',
				'updateUserId');
		$this
			->addForeignKey('fk_account_receivable_update_user_id', 'erp_account_receivable',
				'updateUserId', 'erp_user', 'id', 'SET NULL', 'CASCADE');
		$this->createIndex("account_receivable_project_id", 'erp_account_receivable', 'projectId');
		$this
			->addForeignKey('fk_account_receivable_project_id', 'erp_account_receivable',
				'projectId', 'erp_project', 'id', 'SET NULL', 'CASCADE');

		$this
			->createTable('erp_account_payable',
				array(
					'id' => 'pk',
					'projectId' => 'int',
					'token' => 'string',
					'payDate' => 'date',
					'summary' => 'string',
					'merchantId' => 'int',
					'payee' => 'string',
					'type' => 'int',
					'price' => 'decimal(16,2)',
					'note' => 'string',
					'altMode' => 'boolean',
					'createTime' => 'datetime',
					'createUserId' => 'int',
					'updateTime' => 'datetime',
					'updateUserId' => 'int',
				));
		$this->createIndex("account_payable_create_user_id", 'erp_account_payable', 'createUserId');
		$this
			->addForeignKey('fk_account_payable_create_user_id', 'erp_account_payable',
				'createUserId', 'erp_user', 'id', 'SET NULL', 'CASCADE');
		$this->createIndex("account_payable_update_user_id", 'erp_account_payable', 'updateUserId');
		$this
			->addForeignKey('fk_account_payable_update_user_id', 'erp_account_payable',
				'updateUserId', 'erp_user', 'id', 'SET NULL', 'CASCADE');
		$this->createIndex("account_payable_project_id", 'erp_account_payable', 'projectId');
		$this
			->addForeignKey('fk_account_payable_project_id', 'erp_account_payable', 'projectId',
				'erp_project', 'id', 'SET NULL', 'CASCADE');

		$this->createIndex("account_payable_merchant_id", 'erp_account_payable', 'merchantId');
		$this
			->addForeignKey('fk_account_payable_merchant_id', 'erp_account_payable', 'merchantId',
				'erp_merchant', 'id', 'SET NULL', 'CASCADE');
	}

	public function safeDown() {
		$this->dropTable('erp_account_receivable');
		$this->dropTable('erp_account_payable');
	}
}
